package com.leetcode;

public class RemoveDuplicate
{
	public static void main(String[] args)
	{
		RemoveDuplicate rd = new RemoveDuplicate();
		int[] a = { -1, -1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7 };
		int length = rd.RemoveDuplicates(a);
		System.out.println(length);
		for (int i = 0; i < a.length; i++)
		{
			System.out.println(a[i]);
		}

	}

	public int removeDuplicate(int[] A)
	{
		int n = A.length;
		if (n < 1)
		{
			return 0;
		}

		int i = 1;
		int j = 0;
		int val = A[j];

		while (++j < n)
		{
			OutTxt.Write(val + "--val");
			if (val != A[j])
			{
				OutTxt.Write(A[j] + "--A[" + j + "]");
				val = A[i++] = A[j];
			}
		}
		return i;
	}

	public int RemoveDuplicates(int[] A)
	{
		int n = A.length;
		if (n < 1)
			return 0;

		int j = 0;
		int num = A[0];
		int count = 1;
		int i = 1;

		while (++j < n)
		{
			if (num == A[j] && count < 2)
			{
				A[i++] = A[j];
				count = 2;
			}
			else if (num != A[j])
			{
				num = A[i++] = A[j];
				count = 1;
			}
		}
		return i;
	}
}
